#include "fecudp/udp_endpoint.h"
#include <iostream>

#define     SEND_INTERNAL_MSEC  1
#define     MAX_PACKET_LENGTH   1300

void handleTimter(asio::basic_waitable_timer<std::chrono::system_clock>& looptimer, SpUdpEndpoint client)
{
    static int index = 1;
    if (index > MAX_PACKET_LENGTH)
        index = 1;
    looptimer.expires_from_now(std::chrono::milliseconds(SEND_INTERNAL_MSEC));
    looptimer.async_wait(std::bind(&handleTimter, std::ref(looptimer), client));
    std::string msg(index, 'a' + (index) % 26);
    index++;
    std::cout << "send " << msg[0] << "..., size " << msg.size() << std::endl;
    client->sendto(msg, "239.255.0.1", 4567);
}

int main(int argc, char* argv[])
{
    asio::io_service loop;
    SpUdpEndpoint client = std::make_shared<UdpEndpoint>(loop, "0.0.0.0", 4568);
    client->start();
    asio::basic_waitable_timer<std::chrono::system_clock> loop_timer_(loop);
    loop_timer_.expires_from_now(std::chrono::milliseconds(SEND_INTERNAL_MSEC));
    loop_timer_.async_wait(std::bind(&handleTimter, std::ref(loop_timer_), client));

    loop.run();

    return 0;
}